<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<div class="panel border-back" id="write_goods_info_div">
	<div class="panel-body">
		<div class="line-big">
			<div class="xl5 text-left">
				<button class="button border-blue" id="select_all_order_id">
					<span class="icon-star"></span> 全选
				</button>
				<button class="button border-blue" id="reverse_select_all_order_id">
					<span class="icon-star-half-empty"></span> 反选
				</button>
			</div>
			<div class="xl2 text-center">
				<div class="field field-icon-right" title="查找买家">
					<span class="icon icon-search" id="search_buyer_button"></span>
					<input type="text" class="input radius-rounded" id="keyword_of_buyer_input" value="${param.k }" placeholder="买家编号,用户名,手机号,微信号" />
				</div>
			</div>
			<div class="xl5 text-right">
				<a class="button bg-blue" target="_blank" href="file/buyer_export_record.xlsx">
					<span class="icon-download"></span> 下载全部买家Excel
				</a>
			</div>
		</div>

	</div>
	<div class="panel-foot bg-yellow-light border-back">
		<div class="line-big">
			<div class="xl3 text-center border-small border-right border-blue">用户信息</div>
			<div class="xl2 text-center border-small border-right border-blue">绑定信息</div>
			<div class="xl1 text-center border-small border-right border-blue">积分</div>
			<div class="xl1 text-center border-small border-right border-blue">买家状态</div>
			<div class="xl2 text-center border-small border-right border-blue">用户分享二维码</div>
			<div class="xl3 text-center">操作</div>
		</div>
	</div>
	<ul class="list-group list-striped">
		<c:forEach items="${buyerList }" var="b" varStatus="bStat">
			<li id="li_${b.buyerId }">
				<div class="line-big">
					<div class="xl5 text-left">
						<input class="buyer_id_check_box" type="checkbox" data-id="${b.buyerId }" data-li="#li_${b.buyerId }">
						<strong class="margin-left"> <span class="icon-file-text-o margin-left"></span> 用户编号：${b.buyerId }
						</strong>
						<c:if test="${b.buyerRegisterTime!=null }">
							<span class="icon-clock-o"></span>
							注册时间：<fmt:formatDate value="${b.buyerRegisterTime }" pattern="yyyy-MM-dd HH:mm" />
						</c:if>
						<c:if test="${b.buyerType!=null&&b.buyerType!='' }">
							<span>(${b.buyerType })</span>
						</c:if>
					</div>
					<div class="xl7 text-left">
						<c:if test="${b.buyerRealName!=null&&b.buyerRealName!='' }">
							<span class="icon-user"></span> 真实姓名：${b.buyerRealName}。
						</c:if>
						<c:if test="${b.buyerPeopleId!=null&&b.buyerPeopleId!='' }">
							<span class="icon-credit-card"></span> 身份证号：${b.buyerPeopleId}。
						</c:if>
					</div>
				</div>
			</li>
			<li id="li_${b.buyerId }_2">
				<div class="line-big">
					<div class="xl1 text-center">
						<img class="center-block img-responsive" style="max-height: 60px; max-width: 60px;" src="${b.buyerHeadimgurl }" />
					</div>
					<div class="xl2 text-center">
						<h5 class="text-left">
							<strong> ${b.buyerNickname } </strong>
							<c:if test="${b.buyerName!=null&&b.buyerName!='' }">
							(${b.buyerName })
							</c:if>
						</h5>
						<h6 class="text-left G-MarginTop5">
							<c:if test="${b.buyerCountry!=null&&b.buyerCountry!='' }">
							${b.buyerCountry }
							</c:if>
							<c:if test="${b.buyerProvince!=null&&b.buyerProvince!='' }">
							${b.buyerProvince }
							</c:if>
							<c:if test="${b.buyerCity!=null&&b.buyerCity!='' }">
							${b.buyerCity }
							</c:if>
						</h6>
						<c:if test="${b.buyerSex!=null&&b.buyerSex!='' }">
							<h6 class="text-left G-MarginTop5">${b.buyerSex=='1'?'男':'女' }</h6>
						</c:if>
					</div>
					<div class="xl2 text-left">
						<c:if test="${b.buyerWechat!=null&&b.buyerWechat!='' }">
							<h6 class="text-left" title="微信OPENID：${b.buyerWechat }">微信号：${b.buyerWechat }</h6>
						</c:if>
						<c:if test="${b.buyerPhone!=null&&b.buyerPhone!='' }">
							<h6 class="text-left G-MarginTop5">手机：${b.buyerPhone }</h6>
						</c:if>
						<c:if test="${b.buyerEmail!=null&&b.buyerEmail!='' }">
							<h6 class="text-left G-MarginTop5">邮箱：${b.buyerEmail }</h6>
						</c:if>
						<c:if test="${b.buyerQq!=null&&b.buyerQq!='' }">
							<h6 class="text-left G-MarginTop5">QQ号：${b.buyerQq }</h6>
						</c:if>
						<c:if test="${b.buyerIntroducer!=null&&b.buyerIntroducer!='' }">
							<h6 class="text-left G-MarginTop5">介绍人：${b.buyerIntroducer }</h6>
						</c:if>
					</div>
					<div class="xl1 text-center">
						<strong class="G-MarginTop10">${b.buyerPoints }</h6></strong>
					</div>
					<div class="xl1 text-center">
						<c:choose>
							<c:when test="${b.buyerStatus=='未激活' }">
								<span class="badge bg-default G-MarginTop5">未激活</span>
							</c:when>
							<c:when test="${b.buyerStatus=='使用中' }">
								<span class="badge bg-blue G-MarginTop5">使用中</span>
							</c:when>
							<c:when test="${b.buyerStatus=='冻结中' }">
								<span class="badge bg-red G-MarginTop5">冻结中</span>
							</c:when>
						</c:choose>
						<c:choose>
							<c:when test="${b.buyerType!=null&&b.buyerType!='' }">
								<br>
								<span class="badge bg-yellow G-MarginTop5">${b.buyerType }</span>
							</c:when>
						</c:choose>
					</div>
					<div class="xl2">
						<c:if test="${b.buyerQrcodeId!=null&&b.buyerQrcodeId!='' }">
							<h6 class="text-center">
								开始时间：
								<fmt:formatDate value="${b.buyerQrcodeBeginTime }" pattern="yyyy-MM-dd HH:mm" />
							</h6>
							<h6 class="text-center G-MarginTop5">
								结束时间：
								<fmt:formatDate value="${b.buyerQrcodeEndTime }" pattern="yyyy-MM-dd HH:mm" />
							</h6>
							<h6 class="text-center G-MarginTop5">
								<a target="_blank" class="tips" href="${b.buyerQrcodeUrl }" data-toggle="hover" content='<img src="${b.buyerQrcodeUrl }" width="200px">' data-place="top">
									<span class="icon-qrcode text-big"></span>
								</a>
								<div class="button-group margin-left">
									<button type="button" class="button button-little dropdown-toggle">
										下载二维码 <span class="downward"></span>
									</button>
									<ul class="drop-menu text-left">
										<li style="padding: 0px !important;">
											<a target="_blank" href="${fn:replace(b.buyerQrcodeUrl, '.jpg', '_258.jpg')}">下载258px大小</a>
										</li>
										<li style="padding: 0px !important;">
											<a target="_blank" href="${fn:replace(b.buyerQrcodeUrl, '.jpg', '_344.jpg')}">下载344px大小</a>
										</li>
										<li style="padding: 0px !important;">
											<a target="_blank" href="${fn:replace(b.buyerQrcodeUrl, '.jpg', '_430.jpg')}">下载430px大小(推荐)</a>
										</li>
										<li style="padding: 0px !important;">
											<a target="_blank" href="${fn:replace(b.buyerQrcodeUrl, '.jpg', '_860.jpg')}">下载860px大小</a>
										</li>
										<li style="padding: 0px !important;">
											<a target="_blank" href="${fn:replace(b.buyerQrcodeUrl, '.jpg', '_1280.jpg')}">下载1280px大小</a>
										</li>
									</ul>
								</div>
							</h6>
						</c:if>
					</div>
					<div class="xl3 text-center">
						<c:choose>
							<c:when test="${b.buyerStatus=='未激活' }">
							</c:when>
							<c:when test="${b.buyerStatus=='使用中' }">
								<button class="set_buyer_forever_qrcode_button button bg-blue button-little" data-id="${b.buyerId }" data-li="#li_${b.buyerId }">
									<span class="icon-qrcode"></span> 设置永久二维码
								</button>
								<button class="set_buyer_special_commission_button button bg-blue button-little" data-id="${b.buyerId }" data-li="#li_${b.buyerId }">设置佣金</button>
							</c:when>
							<c:when test="${b.buyerStatus=='冻结中' }">
							</c:when>
						</c:choose>
						<button class="buyer_need_update_button button button-little bg-blue" data-id="${b.buyerId }">
							<span class="icon-pencil"></span> 修改
						</button>
					</div>
				</div>
			</li>
		</c:forEach>
	</ul>
	<div class="panel-foot bg-white border-back" id="buyer_list_pages" data-url="pages_button" data-index="${page.currentIndex}" data-pages="${page.totalPages}"
		data-href="shop/show_buyer_list?s=${param.s }&k=${param.k }&i="></div>
</div>

<div id="see_comment_dialog"></div>

<div id="see_goods_history_dialog"></div>

<a id="a_link_for_data_href" target="_blank" href="">
	<span id="a_link_span_for_data_href"></span>
</a>
<script type="text/javascript" src="${basePath }js/pintuer.js"></script>
<script type="text/javascript">
	$(function()
	{
		//设置佣金
		$(".set_buyer_special_commission_button").click(function()
		{
			$("#admin_div").load("shop/show_special_commission_info_list?buyerId=" + $(this).attr("data-id"), {}, function()
			{

			});
		});

		//修改用户信息
		$(".buyer_need_update_button").click(function()
		{
			$("#admin_div").load("shop/shop_update_buyer?id=" + $(this).attr("data-id"), {}, function()
			{

			});
		});

		//设置永久二维码
		$(".set_buyer_forever_qrcode_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认给此用户设置永久二维码吗? 永久二维码数量有限，用完即止。") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_set_buyer_forever_qrcode_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						alert("设置成功，刷新页面可看到最新二维码。");
					}
				},
				//返回类型
				"json");
			});
		});

		//拒绝申请
		$(".refuse_apply_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认拒绝退换货申请吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_refuse_apply_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//确认收到买家的包裹
		$(".confirm_receive_buyer_express_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认收到此买家的包裹了吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_confirm_receive_buyer_express_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//确认已退款给买家
		$(".confirm_send_buyer_money_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认已退款给此买家了吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_confirm_send_buyer_money_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//卖家换货填写快递信息
		$(".send_out_order_return_button").each(function()
		{
			var button_obj = $(this);
			button_obj.click(function()
			{
				$("#admin_div").html("");
				$("#admin_div").load("shop/ajax/order_return/add_express_info.jsp",
				{
					id : button_obj.attr("data-id"),
					temp : new Date()
				}, function()
				{

				});
			});
		});

		$("#select_all_order_id").click(function()
		{
			$(".buyer_id_check_box").attr("checked", true);
		});
		$("#reverse_select_all_order_id").click(function()
		{
			$(".buyer_id_check_box").each(function()
			{
				$(this).attr("checked", !this.checked);
			});
		});
		$("#batch_send_order").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.buyer_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认批量派送这 " + num + " 个订单吗?") == false)
			{
				return false;
			}

			$("#batch_send_order").attr("disabled", "disabled");
			$.post("shop/sp_send_order_do",
			{
				"commonStr" : ids
			}, function(json)
			{
				if (json.success == false)
				{
					alert(json.info);
					$("#batch_send_order").removeAttr("disabled");
				}
				else
				{
					$("#batch_send_order").removeAttr("disabled");
					$("input.buyer_id_check_box:checked").each(function()
					{
						$($(this).attr("data-li")).remove();
						$($(this).attr("data-li") + "_2").remove();
					});
				}
			},
			//返回类型
			"json");
		});
		$("#batch_send_and_print_order_button").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.buyer_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认批量派送这 " + num + " 个订单并打印吗?") == false)
			{
				return false;
			}

			$("#batch_send_order").attr("disabled", "disabled");
			$.post("shop/sp_send_order_do",
			{
				"commonStr" : ids
			}, function(json)
			{
				if (json.success == false)
				{
					alert(json.info);
					$("#batch_send_order").removeAttr("disabled");
				}
				else
				{
					$("#batch_send_order").removeAttr("disabled");
					$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
					$("#a_link_span_for_data_href").click();
					$("input.buyer_id_check_box:checked").each(function()
					{
						$($(this).attr("data-li")).remove();
						$($(this).attr("data-li") + "_2").remove();
					});
				}
			},
			//返回类型
			"json");
		});
		$("#batch_print_order").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.buyer_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认批量打印这 " + num + " 个订单吗?") == false)
			{
				return false;
			}

			$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
			$("#a_link_span_for_data_href").click();
		});
		$("#batch_receive_order").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.buyer_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认这 " + num + " 个订单已经送达了吗?") == false)
			{
				return false;
			}

			$("#batch_receive_order").attr("disabled", "disabled");
			$.post("shop/sp_receive_order_do",
			{
				"commonStr" : ids
			}, function(json)
			{
				if (json.success == false)
				{
					alert(json.info);
					$("#batch_receive_order").removeAttr("disabled");
				}
				else
				{
					$("#batch_receive_order").removeAttr("disabled");
					$("input.buyer_id_check_box:checked").each(function()
					{
						$($(this).attr("data-li")).remove();
						$($(this).attr("data-li") + "_2").remove();
					});
				}
			},
			//返回类型
			"json");
		});
		$(".send_and_print_order_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认派送此订单并打印订单吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("shop/sp_send_order_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
						$("#a_link_span_for_data_href").click();
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});
		$(".print_order_button").each(function()
		{
			$(this).click(function()
			{
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
				$("#a_link_span_for_data_href").click();
			});
		});
		$(".receive_order_button").each(function()
		{
			$(this).click(function()
			{
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("shop/sp_receive_order_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});
		$("#buyer_list_pages").load($("#buyer_list_pages").attr("data-url"),
		{
			"page.currentIndex" : $("#buyer_list_pages").attr("data-index"),
			"page.totalPages" : $("#buyer_list_pages").attr("data-pages"),
			"page.href" : $("#buyer_list_pages").attr("data-href")
		}, function()
		{
		});
		$("#buyer_list_pages").on("click", "button[data-url]", function()
		{
			$("#admin_div").load(encodeURI($(this).attr("data-url")), {}, function()
			{
			});
		});

		$("#search_buyer_button").click(function()
		{
			var keyword = $("#keyword_of_buyer_input").val();
			if (keyword.length <= 0)
			{
				return false;
			}
			$("#admin_div").load(encodeURI("shop/show_buyer_list?s=${param.s}&k=" + keyword), {}, function()
			{
			});
		});
		$("#keyword_of_buyer_input").keydown(function(event)
		{
			if (event.keyCode == 13)
			{
				$("#search_buyer_button").trigger("click");
			}
		});
	});
</script>